package ${package.Controller};

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
<#if swagger2>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
</#if>
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if swagger2>
@Api(tags = "${table.comment!}管理")
</#if>
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${table.entityPath}Service;

    /**
     * 分页查询
     */
    @GetMapping("/page")
<#if swagger2>
    @ApiOperation("分页查询${table.comment!}")
</#if>
    public Page<${entity}> page(@RequestParam(defaultValue = "1") Integer current,
                               @RequestParam(defaultValue = "10") Integer size) {
        return ${table.entityPath}Service.page(new Page<>(current, size));
    }

    /**
     * 查询所有
     */
    @GetMapping("/list")
<#if swagger2>
    @ApiOperation("查询所有${table.comment!}")
</#if>
    public List<${entity}> list() {
        return ${table.entityPath}Service.list();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/{id}")
<#if swagger2>
    @ApiOperation("根据ID查询${table.comment!}")
</#if>
    public ${entity} getById(<#if swagger2>@ApiParam("主键ID") </#if>@PathVariable Long id) {
        return ${table.entityPath}Service.getById(id);
    }

    /**
     * 新增
     */
    @PostMapping
<#if swagger2>
    @ApiOperation("新增${table.comment!}")
</#if>
    public boolean save(<#if swagger2>@ApiParam("${table.comment!}对象") </#if>@RequestBody ${entity} ${table.entityPath}) {
        return ${table.entityPath}Service.save(${table.entityPath});
    }

    /**
     * 修改
     */
    @PutMapping
<#if swagger2>
    @ApiOperation("修改${table.comment!}")
</#if>
    public boolean updateById(<#if swagger2>@ApiParam("${table.comment!}对象") </#if>@RequestBody ${entity} ${table.entityPath}) {
        return ${table.entityPath}Service.updateById(${table.entityPath});
    }

    /**
     * 根据ID删除
     */
    @DeleteMapping("/{id}")
<#if swagger2>
    @ApiOperation("根据ID删除${table.comment!}")
</#if>
    public boolean removeById(<#if swagger2>@ApiParam("主键ID") </#if>@PathVariable Long id) {
        return ${table.entityPath}Service.removeById(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/batch")
<#if swagger2>
    @ApiOperation("批量删除${table.comment!}")
</#if>
    public boolean removeByIds(<#if swagger2>@ApiParam("主键ID列表") </#if>@RequestBody List<Long> ids) {
        return ${table.entityPath}Service.removeByIds(ids);
    }

}
</#if>